package com.chansos.dubbogo.common;

public class Constant {
    public final static String ErrorMessageTitle = "Error";
    public final static String ErrorFileReadFail = "Can not read this file.";
    public final static String ErrorFileWriteFail = "Can not write this file.";

    public final static String MenuGenerateTitle = "Please Choose Go Struct";
    public final static String MenuGenerateAll = "Generate All Go Struct";
    public final static String MenuGenerateOnly = "Only Generate ";

    public final static String GoFileExternal = "go";

    public final static String LineCommentRegexp = "\\/\\/";

    public final static String PackageRegexp = "^package\\s[a-zA-Z_][0-9a-zA-Z_]*$";
    public final static String InitFunctionRegexp = "^func\\sinit\\(\\)\\s\\{$";
    public final static String HessianImportRegexp = "\"github.com/apache/dubbo-go-hessian2\"";

    public final static String GoStructRegexp = "^type\\s[a-zA-Z_][0-9a-zA-Z_]*\\sstruct\\s\\{$";
    public final static String GoStructNameRegexp = "\\s[a-zA-Z_][0-9a-zA-Z_]*\\s(?!\\sstruct\\s)";
    public final static String HessianPOJORegisterRegexp = "\\*[0-9a-zA-Z_]+\\)\\sJavaClassName\\(\\)\\sstring\\s\\{$";
    public final static String HessianPOJONameRegexp = "\\*[0-9a-zA-Z_]+\\)";

    public final static char newLine = '\n';
    public final static char funcEnd = '}';
    public final static char lineTab = '\t';

    public final static String hessianImport = newLine + "import (" + newLine + lineTab + HessianImportRegexp + newLine + ")" + newLine;


    public static String genInitFunctionStatement(String registerPOJOStatement) {
        return newLine + "func init() {" + newLine + registerPOJOStatement + newLine + funcEnd + newLine;
    }

    public static String genRegisterPOJOStatement(String structName) {
        return lineTab + "hessian.RegisterPOJO(&" + structName + "{})";
    }

    public static String genHessianPOJOImplementFunction(String structName) {
        return newLine + "func (*" + structName + ") JavaClassName() string {" + newLine + lineTab + "return \"" + structName + "\"" + newLine + "}" + newLine;
    }
}
